Skip to content

Fix/login 403 logged in and 401 when not logged in#711

Open
SharonStrats wants to merge 3 commits intomainfrom
fix/login-403-logged-in
Open

Fix/login 403 logged in and 401 when not logged in#711
SharonStrats wants to merge 3 commits intomainfrom
fix/login-403-logged-in

Conversation

@SharonStrats
Copy link
Contributor

I get all these red 403 and 401 errors when I'm

  1. Logged in I get the 403 error
  2. when I'm logged out I get 401

these are quite confronting, this is an attempt at messaging instead of the confronting errors.

Copilot AI review requested due to automatic review settings March 15, 2026 20:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses the confusing 401 and 403 error messages displayed to users when they are logged out (401) or logged in but lack permissions (403). Instead of showing alarming alert() popups and throwing errors, the code now logs friendlier messages and gracefully continues execution.

Changes:

  • In ensureLoadedPreferences, the 401/unauthorized handling now sets a warning and returns context instead of showing an alert, and adds regex-based fallback matching for error messages.
  • In ensureLoadedProfile, the function no longer throws when the user is not logged in; instead it logs a message and returns context. Additionally, 403/forbidden and cancel errors during profile loading are treated as non-fatal when the user is already authenticated.
  • Error message display in ensureLoadedProfile's catch block is updated to use a safely extracted message string instead of accessing err.message directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

(
err instanceof CrossOriginForbiddenError ||
err instanceof SameOriginForbiddenError ||
/status:\s*403|forbidden/i.test(message) ||
let m2: string
if (err instanceof UnauthorizedError) {
const errorMessage = err instanceof Error ? err.message : `${err}`
if (err instanceof UnauthorizedError || /status:\s*401|unauthorized/i.test(errorMessage)) {
context.publicProfile = await loadProfile(logInContext.me)
} catch (err) {
const message = err instanceof Error ? err.message : `${err}`
if (/status:\s*401|unauthorized/i.test(message)) {
Comment on lines +190 to +206
const notLoggedInMessage = 'Not logged in, so profile was not loaded.'
debug.log(notLoggedInMessage)
if (context.div && context.dom) {
context.div.appendChild(widgets.errorMessageBlock(context.dom, notLoggedInMessage))
}
return context
}
context.publicProfile = await loadProfile(logInContext.me)
} catch (err) {
const message = err instanceof Error ? err.message : `${err}`
if (/status:\s*401|unauthorized/i.test(message)) {
const notLoggedInMessage = 'Not logged in, so profile was not loaded.'
debug.warn(notLoggedInMessage)
if (context.div && context.dom) {
context.div.appendChild(widgets.errorMessageBlock(context.dom, notLoggedInMessage))
}
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants